// $ANTLR 3.4 D:\\test\\antlr\\TestSql\\CreateTable.g 2012-07-30 18:02:53

	package wxd.mysqlitemanager.parser.create;
	import wxd.mysqlitemanager.share.db.Column;
	import wxd.mysqlitemanager.share.db.TableInfo;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

/**
	this gramar file is used to parse 'create table' SQLs
	@author wang xudong
	@since 2012-7-30
*/
@SuppressWarnings({"all", "warnings", "unchecked"})
public class CreateTableParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "NUMBER", "WS", "'('", "')'", "','", "';'", "'CREATE'", "'KEY'", "'NOT'", "'NULL'", "'PRIMARY'", "'String'", "'TABLE'", "'UNIQUE'", "'['", "']'", "'binary'", "'create'", "'date'", "'float'", "'int'", "'key'", "'long'", "'not'", "'null'", "'primary'", "'table'", "'text'", "'unique'", "'varchar'"
    };

    public static final int EOF=-1;
    public static final int T__7=7;
    public static final int T__8=8;
    public static final int T__9=9;
    public static final int T__10=10;
    public static final int T__11=11;
    public static final int T__12=12;
    public static final int T__13=13;
    public static final int T__14=14;
    public static final int T__15=15;
    public static final int T__16=16;
    public static final int T__17=17;
    public static final int T__18=18;
    public static final int T__19=19;
    public static final int T__20=20;
    public static final int T__21=21;
    public static final int T__22=22;
    public static final int T__23=23;
    public static final int T__24=24;
    public static final int T__25=25;
    public static final int T__26=26;
    public static final int T__27=27;
    public static final int T__28=28;
    public static final int T__29=29;
    public static final int T__30=30;
    public static final int T__31=31;
    public static final int T__32=32;
    public static final int T__33=33;
    public static final int T__34=34;
    public static final int ID=4;
    public static final int NUMBER=5;
    public static final int WS=6;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public CreateTableParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public CreateTableParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return CreateTableParser.tokenNames; }
    public String getGrammarFileName() { return "D:\\test\\antlr\\TestSql\\CreateTable.g"; }



    // $ANTLR start "start"
    // D:\\test\\antlr\\TestSql\\CreateTable.g:15:1: start returns [TableInfo info] : ( 'create' | 'CREATE' ) ( 'table' | 'TABLE' ) ( '[' )? ID ( ']' )? '(' columnDef[$info] ( ',' columnDef[$info] )* ')' ( ';' )? ;
    public final TableInfo start() throws RecognitionException {
        TableInfo info = null;


        Token ID1=null;


              	info = new TableInfo();
              
        try {
            // D:\\test\\antlr\\TestSql\\CreateTable.g:19:2: ( ( 'create' | 'CREATE' ) ( 'table' | 'TABLE' ) ( '[' )? ID ( ']' )? '(' columnDef[$info] ( ',' columnDef[$info] )* ')' ( ';' )? )
            // D:\\test\\antlr\\TestSql\\CreateTable.g:20:2: ( 'create' | 'CREATE' ) ( 'table' | 'TABLE' ) ( '[' )? ID ( ']' )? '(' columnDef[$info] ( ',' columnDef[$info] )* ')' ( ';' )?
            {
            if ( input.LA(1)==11||input.LA(1)==22 ) {
                input.consume();
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            if ( input.LA(1)==17||input.LA(1)==31 ) {
                input.consume();
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            // D:\\test\\antlr\\TestSql\\CreateTable.g:20:41: ( '[' )?
            int alt1=2;
            int LA1_0 = input.LA(1);

            if ( (LA1_0==19) ) {
                alt1=1;
            }
            switch (alt1) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:20:41: '['
                    {
                    match(input,19,FOLLOW_19_in_start49); 

                    }
                    break;

            }


            ID1=(Token)match(input,ID,FOLLOW_ID_in_start52); 

            // D:\\test\\antlr\\TestSql\\CreateTable.g:20:49: ( ']' )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==20) ) {
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:20:49: ']'
                    {
                    match(input,20,FOLLOW_20_in_start54); 

                    }
                    break;

            }


            match(input,7,FOLLOW_7_in_start57); 

            pushFollow(FOLLOW_columnDef_in_start59);
            columnDef(info);

            state._fsp--;


            // D:\\test\\antlr\\TestSql\\CreateTable.g:20:74: ( ',' columnDef[$info] )*
            loop3:
            do {
                int alt3=2;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==9) ) {
                    alt3=1;
                }


                switch (alt3) {
            	case 1 :
            	    // D:\\test\\antlr\\TestSql\\CreateTable.g:20:75: ',' columnDef[$info]
            	    {
            	    match(input,9,FOLLOW_9_in_start62); 

            	    pushFollow(FOLLOW_columnDef_in_start63);
            	    columnDef(info);

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            match(input,8,FOLLOW_8_in_start68); 

            // D:\\test\\antlr\\TestSql\\CreateTable.g:20:101: ( ';' )?
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==10) ) {
                alt4=1;
            }
            switch (alt4) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:20:102: ';'
                    {
                    match(input,10,FOLLOW_10_in_start71); 

                    }
                    break;

            }


            info.setTableName((ID1!=null?ID1.getText():null));

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return info;
    }
    // $ANTLR end "start"



    // $ANTLR start "columnDef"
    // D:\\test\\antlr\\TestSql\\CreateTable.g:23:1: columnDef[TableInfo table] returns [Column column] : ID columnType columnProps[$column] ;
    public final Column columnDef(TableInfo table) throws RecognitionException {
        Column column = null;


        Token ID2=null;
        CreateTableParser.columnType_return columnType3 =null;



        		column = new Column();
        	
        try {
            // D:\\test\\antlr\\TestSql\\CreateTable.g:27:2: ( ID columnType columnProps[$column] )
            // D:\\test\\antlr\\TestSql\\CreateTable.g:28:2: ID columnType columnProps[$column]
            {
            ID2=(Token)match(input,ID,FOLLOW_ID_in_columnDef98); 

            column.setColumnName((ID2!=null?ID2.getText():null));

            pushFollow(FOLLOW_columnType_in_columnDef103);
            columnType3=columnType();

            state._fsp--;


            column.setColumnType((columnType3!=null?input.toString(columnType3.start,columnType3.stop):null));

            pushFollow(FOLLOW_columnProps_in_columnDef109);
            columnProps(column);

            state._fsp--;


            table.addColumn(column);

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return column;
    }
    // $ANTLR end "columnDef"


    public static class columnType_return extends ParserRuleReturnScope {
    };


    // $ANTLR start "columnType"
    // D:\\test\\antlr\\TestSql\\CreateTable.g:34:1: columnType : ( 'varchar' ( '(' NUMBER ')' )? | 'String' | 'int' | 'float' | 'date' | 'binary' | 'long' | 'text' );
    public final CreateTableParser.columnType_return columnType() throws RecognitionException {
        CreateTableParser.columnType_return retval = new CreateTableParser.columnType_return();
        retval.start = input.LT(1);


        try {
            // D:\\test\\antlr\\TestSql\\CreateTable.g:35:2: ( 'varchar' ( '(' NUMBER ')' )? | 'String' | 'int' | 'float' | 'date' | 'binary' | 'long' | 'text' )
            int alt6=8;
            switch ( input.LA(1) ) {
            case 34:
                {
                alt6=1;
                }
                break;
            case 16:
                {
                alt6=2;
                }
                break;
            case 25:
                {
                alt6=3;
                }
                break;
            case 24:
                {
                alt6=4;
                }
                break;
            case 23:
                {
                alt6=5;
                }
                break;
            case 21:
                {
                alt6=6;
                }
                break;
            case 27:
                {
                alt6=7;
                }
                break;
            case 32:
                {
                alt6=8;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;

            }

            switch (alt6) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:35:3: 'varchar' ( '(' NUMBER ')' )?
                    {
                    match(input,34,FOLLOW_34_in_columnType123); 

                    // D:\\test\\antlr\\TestSql\\CreateTable.g:35:13: ( '(' NUMBER ')' )?
                    int alt5=2;
                    int LA5_0 = input.LA(1);

                    if ( (LA5_0==7) ) {
                        alt5=1;
                    }
                    switch (alt5) {
                        case 1 :
                            // D:\\test\\antlr\\TestSql\\CreateTable.g:35:14: '(' NUMBER ')'
                            {
                            match(input,7,FOLLOW_7_in_columnType126); 

                            match(input,NUMBER,FOLLOW_NUMBER_in_columnType128); 

                            match(input,8,FOLLOW_8_in_columnType130); 

                            }
                            break;

                    }


                    }
                    break;
                case 2 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:36:3: 'String'
                    {
                    match(input,16,FOLLOW_16_in_columnType136); 

                    }
                    break;
                case 3 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:37:3: 'int'
                    {
                    match(input,25,FOLLOW_25_in_columnType140); 

                    }
                    break;
                case 4 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:38:3: 'float'
                    {
                    match(input,24,FOLLOW_24_in_columnType144); 

                    }
                    break;
                case 5 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:39:3: 'date'
                    {
                    match(input,23,FOLLOW_23_in_columnType148); 

                    }
                    break;
                case 6 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:40:3: 'binary'
                    {
                    match(input,21,FOLLOW_21_in_columnType152); 

                    }
                    break;
                case 7 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:41:3: 'long'
                    {
                    match(input,27,FOLLOW_27_in_columnType157); 

                    }
                    break;
                case 8 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:42:3: 'text'
                    {
                    match(input,32,FOLLOW_32_in_columnType161); 

                    }
                    break;

            }
            retval.stop = input.LT(-1);


        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "columnType"



    // $ANTLR start "columnProps"
    // D:\\test\\antlr\\TestSql\\CreateTable.g:44:1: columnProps[Column column] : (a= ( 'not' | 'NOT' ) ( 'null' | 'NULL' ) )? (b= ( 'primary' | 'PRIMARY' ) ( 'key' | 'KEY' ) )? (c= ( 'unique' | 'UNIQUE' ) )? ;
    public final void columnProps(Column column) throws RecognitionException {
        Token a=null;
        Token b=null;
        Token c=null;

        try {
            // D:\\test\\antlr\\TestSql\\CreateTable.g:45:2: ( (a= ( 'not' | 'NOT' ) ( 'null' | 'NULL' ) )? (b= ( 'primary' | 'PRIMARY' ) ( 'key' | 'KEY' ) )? (c= ( 'unique' | 'UNIQUE' ) )? )
            // D:\\test\\antlr\\TestSql\\CreateTable.g:46:2: (a= ( 'not' | 'NOT' ) ( 'null' | 'NULL' ) )? (b= ( 'primary' | 'PRIMARY' ) ( 'key' | 'KEY' ) )? (c= ( 'unique' | 'UNIQUE' ) )?
            {
            // D:\\test\\antlr\\TestSql\\CreateTable.g:46:2: (a= ( 'not' | 'NOT' ) ( 'null' | 'NULL' ) )?
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==13||LA7_0==28) ) {
                alt7=1;
            }
            switch (alt7) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:46:3: a= ( 'not' | 'NOT' ) ( 'null' | 'NULL' )
                    {
                    a=(Token)input.LT(1);

                    if ( input.LA(1)==13||input.LA(1)==28 ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }


                    if ( input.LA(1)==14||input.LA(1)==29 ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }


                    }
                    break;

            }


            if(a != null) column.setNullable(false);

            // D:\\test\\antlr\\TestSql\\CreateTable.g:47:2: (b= ( 'primary' | 'PRIMARY' ) ( 'key' | 'KEY' ) )?
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==15||LA8_0==30) ) {
                alt8=1;
            }
            switch (alt8) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:47:3: b= ( 'primary' | 'PRIMARY' ) ( 'key' | 'KEY' )
                    {
                    b=(Token)input.LT(1);

                    if ( input.LA(1)==15||input.LA(1)==30 ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }


                    if ( input.LA(1)==12||input.LA(1)==26 ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }


                    }
                    break;

            }


            if(b != null) column.setPrimaryKey(true); 

            // D:\\test\\antlr\\TestSql\\CreateTable.g:48:2: (c= ( 'unique' | 'UNIQUE' ) )?
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==18||LA9_0==33) ) {
                alt9=1;
            }
            switch (alt9) {
                case 1 :
                    // D:\\test\\antlr\\TestSql\\CreateTable.g:48:3: c= ( 'unique' | 'UNIQUE' )
                    {
                    c=(Token)input.LT(1);

                    if ( input.LA(1)==18||input.LA(1)==33 ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }


                    }
                    break;

            }


            if(c != null) column.setUnique(true);

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "columnProps"

    // Delegated rules


 

    public static final BitSet FOLLOW_set_in_start36 = new BitSet(new long[]{0x0000000080020000L});
    public static final BitSet FOLLOW_set_in_start42 = new BitSet(new long[]{0x0000000000080010L});
    public static final BitSet FOLLOW_19_in_start49 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ID_in_start52 = new BitSet(new long[]{0x0000000000100080L});
    public static final BitSet FOLLOW_20_in_start54 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_7_in_start57 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_columnDef_in_start59 = new BitSet(new long[]{0x0000000000000300L});
    public static final BitSet FOLLOW_9_in_start62 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_columnDef_in_start63 = new BitSet(new long[]{0x0000000000000300L});
    public static final BitSet FOLLOW_8_in_start68 = new BitSet(new long[]{0x0000000000000402L});
    public static final BitSet FOLLOW_10_in_start71 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_columnDef98 = new BitSet(new long[]{0x000000050BA10000L});
    public static final BitSet FOLLOW_columnType_in_columnDef103 = new BitSet(new long[]{0x000000025004A000L});
    public static final BitSet FOLLOW_columnProps_in_columnDef109 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_34_in_columnType123 = new BitSet(new long[]{0x0000000000000082L});
    public static final BitSet FOLLOW_7_in_columnType126 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_NUMBER_in_columnType128 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_8_in_columnType130 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_16_in_columnType136 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_25_in_columnType140 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_24_in_columnType144 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_23_in_columnType148 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_21_in_columnType152 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_27_in_columnType157 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_32_in_columnType161 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_columnProps176 = new BitSet(new long[]{0x0000000020004000L});
    public static final BitSet FOLLOW_set_in_columnProps183 = new BitSet(new long[]{0x0000000240048002L});
    public static final BitSet FOLLOW_set_in_columnProps197 = new BitSet(new long[]{0x0000000004001000L});
    public static final BitSet FOLLOW_set_in_columnProps203 = new BitSet(new long[]{0x0000000200040002L});
    public static final BitSet FOLLOW_set_in_columnProps217 = new BitSet(new long[]{0x0000000000000002L});

}